/*
 * ServerCommands.hpp
 *
 *  Created on: 15 mei 2013
 *      Author: maarten
 */

#ifndef SERVERSTATES_HPP_
#define SERVERSTATES_HPP_

#define STATE_LOGON 0
#define STATE_IDLE 1
#define STATE_UPLOAD 2
#define STATE_DOWNLOAD 3

#include "ClientConnection.hpp"
#include "Message.hpp"

#include <string>
#include <vector>
#include <sstream>

#include <sys/time.h>

class ServerStates {
public:
	ServerStates(ClientConnection aCon);
	virtual ~ServerStates();

	void handleClient();

private:
	//states
	void logonState(Message aMessage);
	void idleState(Message aMessage);
	void uploadState(Message aMessage);
	void downloadState(Message aMessage);

	void handleRequestLogon(Message aMessage);
	void sendResponseLogon();

	void handleRequestOverview(Message aMessage);
	void sendResponseOverview(std::string path);

	void handleRequestUploadPrepare(Message aMessage);
	void sendResponseUploadPrepare();

	void handleRequestUploadTransfer(Message aMessage);
	void sendResponseUploadTransfer();

	void handleRequestUploadComplete(Message aMessage);
	void sendResponseUploadComplete();

	void handleRequestDownloadPrepare(Message aMessage);
	void sendResponseDownloadPrepare();

	void handleRequestDownloadTransfer(Message aMessage);
	void sendResponseDownloadTransfer();

	void handleRequestDelete(Message aMessage);
	void sendResponseDelete();

	void handleRequestRename(Message aMessage);
	void sendResponseRename();

	void handleRequestAddFolder(Message aMessage);
	void sendResponseAddFolder();

	void sendOnlyMessageType(int messageType);

	void startTime();
	void stopTime(int fileSize);
	int transferSize;

	std::string uploadFileName;
	int uploadFile;
	int uploadSize;

	std::string downloadFileName;
	int downloadFile;

	int state;
	ClientConnection con;

	struct timeval start, finish;
};

#endif /* SERVERSTATES_HPP_ */
